package com.anti.activiti.example;

import com.google.common.collect.Lists;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Author: anTi
 * @Date: 2019/3/18 14:22
 * @Description:
 * @version: 1.0
 */
public class MyTaskListener implements TaskListener {
    private static final Logger LOGGER = LoggerFactory.getLogger(MyTaskListener.class);

    @Override
    public void notify(DelegateTask delegateTask) {
        LOGGER.info("config by Listener");
        String eventName = delegateTask.getEventName();
        LOGGER.info("eventName = {}",eventName);
        if (StringUtils.equals("create",eventName)) {
            delegateTask.addCandidateUsers(Lists.newArrayList("user1", "user2"));
            delegateTask.addCandidateGroup("group1");
            delegateTask.setVariable("key1", "value1");
            delegateTask.setDueDate(DateTime.now().plusDays(3).toDate());
        }else if (StringUtils.equals("complete",eventName)) {
            LOGGER.info("task complete!");
        }
    }
}
